/*******************************************************************************
  Name: stddef.h
  Copyright: Kieran Foot 2009
  Author: Kieran Foot
  Date: 13/06/09 18:57
  Description: Standard definitions
*******************************************************************************/

#include <_ansi.h>
#include <MGOS.h>

#ifndef __STDDEF_H__
#define __STDDEF_H__

_BEGIN_STD_C

#if defined(NULL)
    #undef NULL
#endif
#if defined(__cplusplus)
    #define NULL 0
#else
    #define NULL ((void *)0)
#endif

#if defined(offsetof)
    #undef offsetof
#endif
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

typedef unsigned int size_t;

#define WCHAR_SIZE (MGOS_WIDE_CHAR_SIZE / 8)
#if WCHAR_SIZE == 1 // 8 Bits
   typedef unsigned char wchar_t;
#elif WCHAR_SIZE == 2 // 16 Bits
   typedef unsigned short wchar_t;
#elif WCHAR_SIZE == 3 // 24 Bits
   typedef unsigned int wchar_t;
#elif WCHAR_SIZE == 4 // 32 Bits
   typedef unsigned int wchar_t;
#elif WCHAR_SIZE == 5 // 40 Bits
   typedef unsigned long long wchar_t;
#elif WCHAR_SIZE == 6 // 48 Bits
   typedef unsigned long long wchar_t;
#elif WCHAR_SIZE == 4 // 56 Bits
   typedef unsigned long long wchar_t;
#elif WCHAR_SIZE == 8 // 64 Bits
   typedef unsigned long long wchar_t;
#else
   #warning Wide char defined as being more then 64 Bits
#endif

#if MGOS_TARGET_BITS == 32
    typedef unsigned int ptrdiff_t;
#elif MGOS_TARGET_BITS == 64
    typedef unsigned long long ptrdiff_t;
#endif

_END_STD_C

#endif
